//
//  UIColor+AG.swift
//  ASW
//
//  Created by zhuxuhong on 2020/11/21.
//

import UIKit

extension UIColor {
    public func alpha(_ value: CGFloat) -> UIColor{
        return withAlphaComponent(value)
    }
    
    public var reverted: UIColor {
        var r:CGFloat = 0, g:CGFloat = 0, b:CGFloat = 0
        getRed(&r, green: &g, blue: &b, alpha: nil)
        return UIColor(red:1.0-r, green: 1.0-g, blue: 1.0-b, alpha: 1)
    }
}

extension UIColor {
    public var a05: UIColor {
        return alpha(0.05)
    }
    public var a1: UIColor {
        return alpha(0.1)
    }
    public var a2: UIColor {
        return alpha(0.2)
    }
    public var a3: UIColor {
        return alpha(0.3)
    }
    public var a4: UIColor {
        return alpha(0.4)
    }
    public var a5: UIColor {
        return alpha(0.5)
    }
    public var a6: UIColor {
        return alpha(0.6)
    }
    public var a7: UIColor {
        return alpha(0.7)
    }
    public var a8: UIColor {
        return alpha(0.8)
    }
    public var a9: UIColor {
        return alpha(0.9)
    }
    public var a10: UIColor {
        return alpha(1)
    }
}

extension UIColor {
    public func bw_toImage(
        size: CGSize = .bw_with(both: 30),
        opaque: Bool = false
    ) -> UIImage? {
        let v = UIView(frame: .init(origin: .zero, size: size))
        v.backgroundColor = self
        return v.bw_renderToImage(opaque: opaque)
    }
}

